package com.yujistu.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.andexert.library.RippleView;
import com.yujistu.R;
import com.yujistu.fragment.SearchingFragment;

/**
 * Created by Win on 2015/11/6.
 */
public class SearchingActivity extends BaseActivity {


    EditText    baseItemET;
    ImageView   closeIV;
    RippleView  cancelRV;

    String  mCloseIV;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);

        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();

        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        SearchingFragment fragment = new SearchingFragment();

        //  RelativeLayout layoutRL = (RelativeLayout)findViewById(R.id.rll_container);
        ft.add(R.id.rll_container, fragment);
        ft.commit();
    }

    private void initView() {
        baseItemET = (EditText)findViewById(R.id.baseItemET);

        closeIV = (ImageView)findViewById(R.id.searchingIV);
        closeIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 baseItemET.setText(" ");

            }
        });
       baseItemET.addTextChangedListener(new TextWatcher() {
           @Override
           public void beforeTextChanged(CharSequence s, int start, int count, int after) {

           }

           @Override
           public void onTextChanged(CharSequence s, int start, int before, int count) {

           }

           @Override
           public void afterTextChanged(Editable s) {
               mCloseIV = s.toString();
               if (TextUtils.isEmpty(mCloseIV)) {
                   closeIV.setVisibility(View.GONE);
               } else {
                   closeIV.setVisibility(View.VISIBLE);
               }
           }
       });

        cancelRV = (RippleView)findViewById(R.id.filtrateRV);
        cancelRV.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                finish();
            }
        });
    }
}
